package com.hlingsoft.kkh.action.v20;

import com.hlingsoft.kkh.action.BaseAction;
import com.hlingsoft.kkh.entity.*;
import com.hlingsoft.kkh.util.Common;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by selbylei on 2015/6/26.
 */
@Controller
@RequestMapping("v20/feedback")
public class FeedbackAction extends BaseAction {


    /**
     * 添加意见反馈
     * @param userId
     * @param content
     * @param email
     * @param request
     * @return
     */
    @RequestMapping(value = "/add.json")
    @ResponseBody
    public Map<String, Object> add(
            @RequestParam(value = "userId") long userId,
            @RequestParam(value = "content") String content,
            @RequestParam(value = "email") String email,
            HttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {

            if (request.getMethod()=="GET"){
                content=Common.encodeStr(content);
                email=Common.encodeStr(email);
            }
            Date now = new Date();
            Feedback feedback = new Feedback();
            feedback.setAppUserId(userId);
            feedback.setContent(content);
            feedback.setEmail(email);
            feedback.setCreateTime(now);
            feedback.setUpdateTime(now);

            feedbackDao.addFeedback(feedback);
            resultMap.put("feedback",feedback);
            resultMap.put("result",true);
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", false);
        }
        return resultMap;
    }

}
